package cn.itcast.zuoyebang.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;

import cn.itcast.zuoyebang.LoginActivity;
import cn.itcast.zuoyebang.R;
import cn.itcast.zuoyebang.utils.PreferenceUtils;


public class Table4Fragment extends Fragment implements View.OnClickListener {



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_table4, container, false);
        RelativeLayout info = view.findViewById(R.id.info);
        LinearLayout setting = view.findViewById(R.id.setting);
        TextView userName = view.findViewById(R.id.username);

        info.setOnClickListener(this);
        setting.setOnClickListener(this);
        userName.setOnClickListener(this);

        if(  PreferenceUtils.getInstance(getContext()).readLoginStatus()  ) {
            userName.setText(PreferenceUtils.getInstance(getContext()).readUserName());
        } else {
            userName.setText("点击登录");
        }
        return view;
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.setting:
                if(  PreferenceUtils.getInstance(getContext()).readLoginStatus()  ) {
                    //已经登录了  跳转到设置页面
                } else {
                    Snackbar.make(view,"请登录", Snackbar.LENGTH_SHORT).show();
                }
                break;
            case R.id.info:
                if(  PreferenceUtils.getInstance(getContext()).readLoginStatus()  ) {
                    //已经登录了  跳转到个人资料页面
                } else {
                    //未登录 跳转到登录页面
                    Intent intent = new Intent( getContext() , LoginActivity.class);
                    getContext().startActivity(intent);
                }
                break;

        }
    }
}